﻿<template>
  <div>
      <h3>当前求和:{{sum}}</h3>
      <select name="" id="" v-model.number="n">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
      </select>
      <button @click="add">+</button>
      <button @click="jf">-</button>
      <button @click="jAdd">当前求和为奇数再加</button>
      <button @click="delayAdd">等一等再加</button>
  </div>
</template>

<script>
    export default {
        name: 'Add',
        components:{},
        data() {
            return {
                n:1,
                sum:0
            }
        },
        methods: {
            add(){
                this.sum += this.n
            },
            jf(){
                this.sum -= this.n
            },
            jAdd(){
                if(this.sum % 2 !== 0){
                    this.sum += this.n
                }
            },
            delayAdd(){
                setTimeout(()=>{
                    this.sum += this.n
                },2000)
            }
        },
    }
</script>

<style scoped>

</style>